package com.sezi.blog.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
/**
 * 角色实体类
 * @author yuanyi
 * @Date 2015-4-16
 * @version 1.0
 */
@Entity
@Table(name="b_role")
public class Role {
	/**id*/
	private Long id;
	/**角色名称*/
	private String name;
	/**是否启用*/
	private boolean started;
	/**角色的权限*/
	private List<Permission> permissions;
	/**拥有此角色的用户*/
	private List<User> users;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public boolean isStarted() {
		return started;
	}
	
	public void setStarted(boolean started) {
		this.started = started;
	}
	
	@ManyToMany
	@JoinTable(name="role_permission",
	joinColumns={@JoinColumn(name="role_id",referencedColumnName="id")},
	inverseJoinColumns={@JoinColumn(name="permission_id",referencedColumnName="id")})
	public List<Permission> getPermissions() {
		return permissions;
	}
	
	public void setPermissions(List<Permission> permissions) {
		this.permissions = permissions;
	}
	
	@ManyToMany
	@JoinTable(name="role_permission",
	joinColumns={@JoinColumn(name="role_id",referencedColumnName="id")},
	inverseJoinColumns={@JoinColumn(name="user_id",referencedColumnName="id")})
	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}
}
